package cn.longg.mapper;

import org.apache.ibatis.annotations.Param;
import org.springframework.util.StringUtils;

public class ArticleMapperSqlProvider {

    public String selectByPage(String title){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from article ");
        if(!StringUtils.isEmpty(title)){
            sb.append("where title like concat('%',#{title},'%')");
        }
        return sb.toString();
    }

    public String selectFavByPage(@Param("title") String title,@Param("uId") Integer uId){
        StringBuilder sb = new StringBuilder();
        sb.append("select * from article where EXISTS(select 1 from favorite where u_id = #{uId} and a_id = id) ");
        if(!StringUtils.isEmpty(title)){
            sb.append("and title like CONCAT('%',#{title},'%')");
        }
        return sb.toString();
    }
}
